#include "cell.h"
#include "building.h"
#include "city.h"
#include <vector>
#include <iostream>
using namespace std;
const std::string CLEAR = "\033[0m";
const std::string GREEN = "\033[42m";
const std::string BLUE = "\033[44m";
const std::string RED = "\033[41m";
const std::string CYAN = "\033[46m";
const std::string BROWN = "\033[43m";
const std::string GRAY = "\033[47m";

void cell::set_employment(int x, int y) {
	if(get_building().get_type() == RESIDENTIAL) {
		_employment_vector = vector<pair<int,int>>();
		_employment_vector.push_back(pair<int,int>(x,y));
	} else {
		_employment_vector.push_back(pair<int,int>(x,y));
	}
}

void cell::delete_employment(int x, int y) {
	vector<pair<int,int>>::iterator it = _employment_vector.begin();
	bool found = false;
	while(it != _employment_vector.end() && !found) {
		if(x == (*it).first && y == (*it).second) {
			_employment_vector.erase(it);
			found = true;
		}
		++it;
	}
}

void cell::clear_employment() {
	_employment_vector.clear();
}

bool cell::has_needs_met() {
	bool has_needs_met = false;
	if(0 == _building_time)
		has_needs_met = ((_electricity > 0) && (_access > 0));
	return has_needs_met;
}

std::string cell::color_by_type(){
	std::string color_ansi;
	switch(get_building().get_type()){
		case LAND: color_ansi = BROWN; break;
		case ROAD: color_ansi = CLEAR; break;
		case RESIDENTIAL: color_ansi = GREEN; break;
		case POWER_STATION: color_ansi = RED; break;
		case INDUSTRY: color_ansi = GRAY; break;
		case SHOPS: color_ansi = BLUE; break;
		case WATER_STATION: color_ansi = CYAN; break;
	}
	return color_ansi;
}

std::string cell::color_by_traffic(){
	std::string color_ansi;
	if(_traffic > 0)
		color_ansi = GRAY;
	else
		color_ansi = CLEAR;
	return color_ansi;
}

std::string cell::color_by_access(){
	std::string color_ansi;
	if(_access > 0)
		color_ansi = GRAY;
	else
		color_ansi = CLEAR;
	return color_ansi;
}

std::string cell::color_by_water(){
	std::string color_ansi;
	if(_water > 0)
		color_ansi = BLUE;
	else
		color_ansi = CLEAR;
	return color_ansi;
}

std::string cell::color_by_pollution(){
	std::string color_ansi;
	if(_air_pollution > 0)
		color_ansi = GRAY;
	else
		color_ansi = CLEAR;
	return color_ansi;
}

std::string cell::color_by_electricity(){
	std::string color_ansi;
	if(_electricity > 0)
		color_ansi = BROWN;
	else
		color_ansi = CLEAR;
	return color_ansi;
}

std::string cell::color_by_building_time(){
	std::string color_ansi;
	if(_building_time > 0)
		color_ansi = BROWN;
	else
		color_ansi = CLEAR;
	return color_ansi;
}

std::string cell::clear_color(){ return CLEAR; }

